<template>
  <div>
    <div class="n-layout-page-header">
      <n-card :bordered="false" title="龙头晋级">
        <!--  这是由系统生成的CURD表格，你可以将此行注释改为表格的描述 -->
      </n-card>
    </div>
    <n-card :bordered="false" class="proCard">
      <BasicForm
        @register="register"
        @submit="reloadTable"
        @reset="reloadTable"
        @keyup.enter="reloadTable"
        ref="searchFormRef"
      >
        <template #statusSlot="{ model, field }">
          <n-input v-model:value="model[field]" />
        </template>
      </BasicForm>
      <n-grid cols="9" responsive="screen" :x-gap="12" :y-gap="9">
        <n-gi span="4">
          <n-card :bordered="false" size="small" />
          <n-space vertical size="large">
            <n-layout has-sider v-for="ztInfoItem in prevZTInfoRef">
              <n-layout-sider
                collapse-mode="transform"
                :collapsed-width="10"
                :width="120"
                show-trigger="arrow-circle"
                content-style="padding: 24px;"
                bordered
              >
                <n-h2>{{ ztInfoItem.name }}</n-h2>
              </n-layout-sider>

              <n-layout-content content-style="padding: 10px;">
                <div class="flex flex-wrap project-card">
                  <n-data-table
                    :columns="columns"
                    :data="ztInfoItem.list"
                    :bordered="false"
                    size="small"
                    class="my-center"
                    style="text-align: center"
                    striped
                    min-height="150"
                    max-height="150"
                  />
                </div>
              </n-layout-content>
            </n-layout>
          </n-space>
        </n-gi>
        <n-gi span="1">
          <n-list>
            <template #header>
              <n-icon-wrapper :size="120" style="width: 100%" color="white">
                <n-icon :size="120" color="red" :component="ArrowRightOutlined" />
              </n-icon-wrapper>
            </template>
            <template #footer>
              <n-icon-wrapper :size="120" style="width: 100%" color="white">
                <n-icon :size="120" color="red" :component="ArrowRightOutlined" />
              </n-icon-wrapper>
            </template>
            <n-list-item>
              <n-h1 style="writing-mode: vertical-lr; text-align: center; margin-left: 25%">
                涨停板龙头晋级表
              </n-h1>
            </n-list-item>
          </n-list>
        </n-gi>
        <n-gi span="4">
          <n-card :bordered="false" size="small" />
          <n-space vertical size="large">
            <n-layout has-sider v-for="ztInfoItem in ztInfoRef">
              <n-layout-sider
                collapse-mode="transform"
                :collapsed-width="10"
                :width="120"
                show-trigger="arrow-circle"
                content-style="padding: 24px;"
                bordered
              >
                <n-h2>{{ ztInfoItem.name }}</n-h2>
              </n-layout-sider>

              <n-layout-content content-style="padding: 10px;">
                <div class="flex flex-wrap project-card">
                  <n-data-table
                    :columns="columns"
                    :data="ztInfoItem.list"
                    :bordered="false"
                    size="small"
                    class="my-center"
                    style="text-align: center"
                    striped
                    min-height="150"
                    max-height="150"
                  />
                </div>
              </n-layout-content>
            </n-layout>
          </n-space>
        </n-gi>
      </n-grid>
    </n-card>
    <Edit @reloadTable="reloadTable" ref="editRef" />
    <View ref="viewRef" />
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import { useDialog, useMessage } from 'naive-ui';
  import { BasicForm, useForm } from '@/components/Form/index';
  import { usePermission } from '@/hooks/web/usePermission';
  import { getLTJJInfo } from '@/api/stockZtPool';
  import { schemas } from './model';
  import Edit from './edit.vue';
  import View from './view.vue';
  import { createStorage } from '@/utils/Storage';
  import { LATEST_DAY } from '@/store/mutation-types';
  import { ArrowRightOutlined } from '@vicons/antd';
  const dialog = useDialog();
  const message = useMessage();
  const { hasPermission } = usePermission();
  const actionRef = ref();
  const searchFormRef = ref<any>({});
  const viewRef = ref();
  const editRef = ref();
  const batchDeleteDisabled = ref(true);
  const checkedIds = ref([]);

  const [register, {}] = useForm({
    gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
    labelWidth: 80,
    schemas,
  });

  const columns = [
    {
      title: '名字',
      key: 'name',
      width: 80,
    },
    {
      title: '所属行业',
      key: 'industry',
      width: 80,
    },
    {
      title: '最后封板时间',
      key: 'lastFbTime',
      width: 80,
    },
  ];
  const ztInfoRef = ref([]);
  const prevZTInfoRef = ref([]);
  const loadLTJJInfo = async (res) => {
    return await getLTJJInfo({ ...res });
  };
  onMounted(() => {
    const storage = createStorage({ storage: localStorage });
    let latestDay = Date.parse(storage.get(LATEST_DAY));
    loadLTJJInfo({ date: latestDay }).then((res) => {
      ztInfoRef.value = res.list;
      prevZTInfoRef.value = res.prev_list;
    });
  });

  function reloadTable() {
    loadLTJJInfo({ ...searchFormRef.value?.formModel }).then((res) => {
      ztInfoRef.value = res.list;
      prevZTInfoRef.value = res.prev_list;
    });
  }
</script>

<style lang="less" scoped></style>
